package com.example.hearthstoneagain;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

public class BancodeDados extends SQLiteOpenHelper {

	Context context;
	
	public BancodeDados(Context context) {
		super(context, "bancocartas", null, 1);
		this.context = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		String sql = "CREATE TABLE cartas ( name TEXT PRIMARY KEY, rarity TEXT, classe TEXT, cost INTEGER, attack INTEGER, health INTEGER, tipo TEXT, "
				+ "battlecry TEXT, charge TEXT, combo TEXT, deathrattle TEXT, divineshield TEXT, enrage TEXT, overload TEXT, "
				+ "spelldamage TEXT, stealth TEXT, taunt TEXT, windfury TEXT , texto TEXT, url TEXT, comentario TEXT)";
		db.execSQL(sql);
		
		Cartas carts = new Cartas();
		
		for(int i=0;i<carts.size();i++) {
			sql = "INSERT INTO cartas (name,rarity,classe,cost,attack,health,tipo,battlecry,charge,combo,deathrattle,divineshield,enrage,overload,spelldamage,"
					+ "stealth,taunt,windfury,texto,url,comentario) VALUES ('"+carts.get(i).getName()+"','"+carts.get(i).getRarity()+"','"+carts.get(i).getClasse()+"',"+
					carts.get(i).getCost()+","+carts.get(i).getAttack()+","+carts.get(i).getHealth()+",'"+carts.get(i).getTipo()+"','"+
					carts.get(i).isBattlecry()+"','"+carts.get(i).isCharge()+"','"+carts.get(i).isCombo()+"','"+carts.get(i).isDeathrattle()+
					"','"+carts.get(i).isDivineshield()+"','"+carts.get(i).isEnrage()+"','"+carts.get(i).isOverload()+"','"+carts.get(i).isSpelldamage()+
					"','"+carts.get(i).isStealth()+"','"+carts.get(i).isTaunt()+"','"+carts.get(i).isWindfury()+"','"+carts.get(i).getTexto()+"','"+
					carts.get(i).getUrl()+"','"+carts.get(i).getComentario()+"')";
			db.execSQL(sql);
		}
		
		sql = "CREATE TABLE decks ( name TEXT PRIMARY KEY, classe TEXT, custo INTEGER, cartas TEXT, comentario TEXT)";
		db.execSQL(sql);
		
		Decks decks = new Decks();
		
		for(int i=0;i<decks.size();i++) {
			sql = "INSERT INTO decks (name,classe,custo,cartas,comentario) VALUES ('"+decks.get(i).getNome()+"','"+decks.get(i).getClasse()+"',"+
					decks.get(i).getCusto()+",'"+decks.get(i).getCartas()+"','"+decks.get(i).getComentario()+"')";
			db.execSQL(sql);
		}
		
		sql = "CREATE TABLE news ( titulo TEXT PRIMARY KEY, texto TEXT, img INTEGER)";
		db.execSQL(sql);
		
		Noticias noticias = new Noticias();
		
		for(int i=0;i<noticias.size();i++) {
			sql = "INSERT INTO news (titulo,texto,img) VALUES ('"+noticias.get(i).getTitulo()+"','"+noticias.get(i).getTexto()+"',"+noticias.get(i).getImg()+")";
			db.execSQL(sql);
		}
		
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		String sql = "DROP TABLE IF EXISTS cartas";
		arg0.execSQL(sql);
		sql = "DROP TABLE IF EXISTS decks";
		arg0.execSQL(sql);
		sql = "DROP TABLE IF EXISTS news";
		arg0.execSQL(sql);
		onCreate(arg0);
		
	}

}
